import {
  Column,
  CreateDateColumn,
  Entity,
  JoinTable,
  ManyToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Role } from './role.entity';
import { Exclude, Expose } from 'class-transformer';
@Exclude()
@Entity({ name: 'users' })
export class UserEntity {
  @Expose()
  @PrimaryGeneratedColumn()
  id: number;

  @Expose()
  @Column({ length: 50, comment: '用户名', unique: true })
  username: string;

  @Column({ length: 50, comment: '密码' })
  password: string;

  @Expose()
  @Column({ name: 'nick_name', length: 50, comment: '昵称' })
  nickName: string;

  @Expose()
  @Column({ length: 50, comment: '邮箱' })
  email: string;

  @Expose()
  @Column({ length: 100, comment: '头像', nullable: true })
  headPic: string;

  @Expose()
  @Column({ length: 20, comment: '手机号', nullable: true })
  phoneNumber: string;

  @Expose()
  @Column({ comment: '是否冻结', default: false })
  isFrozen: boolean;

  @Expose()
  @Column({ comment: '是否管理员', default: false })
  isAdmin: boolean;

  @Expose()
  @CreateDateColumn()
  createTime: Date;

  @Expose()
  @UpdateDateColumn()
  updateTime: Date;

  @Expose()
  @ManyToMany(() => Role)
  @JoinTable({
    name: 'user_roles',
  })
  roles: Role[];
}
